
class SimulationAction:
    def start(self, mol, efunc):
        pass
    
    def finish(self, mol, efunc):
        pass

    def act(self, mol, i, efunc):
        raise NotImplementedError()
    
class SimulationActionSet(SimulationAction):
    def __init__(self):
        self.list = []

    def start(self, mol, efunc):
        for i in self.list:
            i[0] = 0
            i[2].start(mol, efunc)

    def finish(self, mol, efunc):
        for i in self.list:
            i[2].finish(mol, efunc)            
            
    def act(self, mol, step, efunc):
        for i in self.list:
            if i[0] < step:
                i[0] += i[1]
                i[2].act(mol, step, efunc)
                
    def reset_ticks(self):
        for i in self.list:
            i[0] = 0
            
    def add(self, action, ticks = 1, start = 0):
        self.list.append((start, ticks, action,))
        
    def remove(self, action):
        for i in self.list:
            if i[2] == action:
                self.list.remove(i)
                break

    def run(self, mol, nstep, efunc):
        self.start(mol, efunc)
        for i in xrange(1, nstep+1):
            self.act(mol, i, efunc)
        self.finish(mol, efunc)

